﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;
using System.IO;
using System.Dynamic;
using FluorineFx.Json;

namespace lxwmvc
{
    /// <summary>
    /// 债权转让
    /// </summary>
    public static partial class huifucontroller
    {

        /// <summary>

        /// </summary>
        /// <param name="pb"></param>
        //public static void huifu_chongzhi(pagebase pb)
        //{
            
        //}


        //债券转让的设计台垃圾了，需要重新设计

        //首先需要先发起债券转让申请，里面包含装让多少金额，折让率，是否有期限，是否允许可以购买一部分，购买其实金额多少。

        //债权转让市场和一手标的市场表现可以不一样。。。

        /// <summary>
        /// 债权投资记录
        /// </summary>
        /// <param name="pjkjbxxid"></param>
        /// <param name="touzirenid"></param>
        /// <param name="tzjine"></param>
        static void huifu_toubiao_shengchengzhaiquantouzijilu(supermodel pjkjbxx, string touzirenid, decimal tzjine)
        {
            //var pjkjbxxid = pjkjbxx.get<int>("pjkjbxxid");
           
            //supermodel userinfo = core_user.getUserInfo(touzirenid);
            ////生成投资记录
            //int islingtou = 0;
            ////if (P2PHelper.IsInLingTouZu(jiandansql.getstring("SELECT USER_PRIV FROM [dbo].[SysUser] WHERE USER_ID='" + touzirenid + "'")))
            ////{
            ////    islingtou = 1;
            ////}


            //int pjktzjlid = jiandansql.getint("insert into pjktzjl(pjkjbxxid,toubiaorenid,toubiaojine,youxiaojine,toubiaoshijian,zhuangtai,islingtou) values(" + pjkjbxxid + ",'" + touzirenid + "'," + tzjine.tostr() + ",0,GETDATE(),'未支付'," + islingtou + ");select @@identity");

            //DataRow drzhaiquan = jiandansql.getonerow("select * from zhaiquanzhuanrang where pjkjbxxid=" + pjkjbxxid);

            //string sellcustid = core_user.getUsrCustId(pjkjbxx["jiekuanrenid"] + "");

            //string jiekuanrenkehuhao = jiandansql.getstring("select UsrCustId from pjkjbxx p inner join SysUser_kuozhan s on p.jiekuanrenid=s.user_id where p.pjkjbxxid=" + drzhaiquan["oldpjkjbxxid"].tostr());


            ////主动投标记录
            ////跟汇付接口连接。
            //CreditAssign objsend = new CreditAssign();
            //objsend.CmdId = "CreditAssign";
            //objsend.MerCustId = HuiFuArg.MerCustId;
            //objsend.SellCustId = sellcustid; //转让人客户号
            //objsend.CreditAmt = tzjine.todecimal().ToString("#0.00");//债权转让出的本金
            //objsend.CreditDealAmt = tzjine.todecimal().ToString("#0.00");//债权转让承接人付给的金额

            //objsend.BidDetails = ("{\"BidDetails\":[{\"BidOrdId\":\"" + drzhaiquan["OrdId"].tostr() + "\",\"BidOrdDate\":\"" + drzhaiquan["OrdDate"].tostr() + "\",\"BidCreditAmt\":\"" + tzjine.todecimal().ToString("#0.00") + "\",\"BorrowerDetails\":[{\"BorrowerCustId\":\"" + jiekuanrenkehuhao + "\",\"BorrowerCreditAmt\":\"" + tzjine.todecimal().ToString("#0.00") + "\",\"PrinAmt\":\"0.00\",\"ProId\":\"\"}]}]}"); //转让明细

            ////手续费
            //Decimal fenzhangjine = tzjine.todecimal() * HuiFuArg.DivFee.todecimal();
            //objsend.Fee = fenzhangjine.ToString("#0.00");
            //objsend.DivDetails = ("[{\"DivAcctId\":\"" + ConfigurationManager.AppSettings["AcctId"].tostr() + "\",\"DivAmt\":\"" + fenzhangjine.ToString("#0.00") + "\"}]"); //分账明细

            //////债权转让承接人客户号
            //objsend.BuyCustId = core_user.getUsrCustId();
           

            //objsend.BgRetUrl = ConfigurationManager.AppSettings["LocalUrl"] + "ploan/zhaiquanzhuanrangreturnbg.html";
            //objsend.RetUrl = ConfigurationManager.AppSettings["LocalUrl"] + "ploan/zhaiquanzhuanrangreturn.html";

            //#region 写入投资流水、转让流水记录

            ////todo 这里需要插入一条到债权转让流水表里面。对应的表为 Mzhaiquanliushui 表里面。
            //supermodel Mzhaiquanliushui = supermodel.create("Mzhaiquanliushui");
            ////todo.start 补充完整里面的信息
            //Mzhaiquanliushui["User_Id"] = HttpContext.Current.Session["g_user_id"].ToString();
            //Mzhaiquanliushui["LogType"] = 0; //0 是代表为处理 1是代表成功 2代表失败
            //Mzhaiquanliushui["SetupDate"] = DateTime.Now;
            //Mzhaiquanliushui["OrdId"] = objsend.OrdId + "";
            //Mzhaiquanliushui["OrdDate"] = objsend.OrdDate + "";//订单日期
            //Mzhaiquanliushui["MerCustId"] = ConfigurationManager.AppSettings["MerCustId"].tostr();
            //Mzhaiquanliushui["SellCustId"] = sellcustid; //转让人客户号
            //Mzhaiquanliushui["CreditAmt"] = tzjine.todecimal().ToString("#0.00");//债权转让出的本金
            //Mzhaiquanliushui["CreditDealAmt"] = tzjine.todecimal().ToString("#0.00");//债权转让承接人付给的金额
            //Mzhaiquanliushui["BidOrdId"] = drzhaiquan["OrdId"].tostr();//被转让的投标订单号
            //Mzhaiquanliushui["BidOrdDate"] = drzhaiquan["OrdDate"].tostr();//被转让的投标订单日期
            //Mzhaiquanliushui["BidCreditAmt"] = tzjine.todecimal().ToString("#0.00");//转让金额
            //Mzhaiquanliushui["BorrowerCustId"] = jiekuanrenkehuhao;//借款人客户号
            //Mzhaiquanliushui["BorrowerCreditAmt"] = tzjine.todecimal().ToString("#0.00");//明细转让金额
            //Mzhaiquanliushui["PrinAmt"] = "0.00";//已还款金额
            //Mzhaiquanliushui["BorrowerCustId"] = jiekuanrenkehuhao;//借款人客户号
            //Mzhaiquanliushui["Fee"] = objsend.Fee.tostr();//扣款手续费
            //Mzhaiquanliushui["DivAcctId"] = ConfigurationManager.AppSettings["AcctId"].tostr();//分账账户号         
            //Mzhaiquanliushui["DivAmt"] = fenzhangjine.ToString("#0.00");//分账金额
            //Mzhaiquanliushui["touzhijiluid"] = pjktzjlid.tostr();//投资记录ID
            //Mzhaiquanliushui["BuyCustId"] = objsend.BuyCustId;//承接人客户号
            //Mzhaiquanliushui["OrdId"] = objsend.OrdId;//订单号
            //Mzhaiquanliushui["OrdDate"] = objsend.OrdDate;//订单日期
            //Mzhaiquanliushui["ProId"] = pjkjbxxid.tostr();
            ////得到插入的主键
            //var ret = Mzhaiquanliushui.saveorupdate();
            //#endregion
            ////插入成功后，把流水的ID传递到实体中 
            ////todo 把主键作为参数传递到汇付的方法里面 返回的地方需要用到这个参数
            //objsend.MerPriv = ret.identity + "";
        }

//        /// <summary>
//        ///  购买债权
//        /// </summary>
//        [SkipFilter()]
//        public void buydebt()
//        {
//            //没有模板
//            this.CancelView();
//            string strSql = "";
//            DataTable dt_jisuan = new DataTable();
//            int pjkjbxxid = RequestHelper.SafeKeyValue("pjkjbxxid").toint32(0);//借款id
//            decimal tzjine = RequestHelper.SafeKeyValue("tzjine").todecimal(0);//投资金额
//            //decimal tzjine_yue = RequestHelper.SafeKeyValue("tzjineyue").todecimal(0);//来自账户余额的金额
//            //string yhids = RequestHelper.SafeKeyValue("yhids");//选中的优惠ids
//            //decimal tzjine_yh = RequestHelper.SafeKeyValue("yhamount").todecimal(0);//来自账户优惠与红包的金额
//            if (HttpContext.Current.Session["g_user_id"].ToString().tostr() == "")
//            {
//                JSHelper.Out("alert('尚未登录，请登录');parent.loginwin();");
//                return;
//            }
//            string userid = HttpContext.Current.Session["g_user_id"].ToString();
//            string zongjine = string.Empty;
//            string dongjieyue = string.Empty;
//            decimal tzjine_yue = Convert.ToDecimal(P2PHelper.gethuifuzhanghuyue(userid, out zongjine, out dongjieyue, 0));//来自汇付余额的金额（Update By 冀兴光）



//            if (tzjine < 0)
//            {
//                jshelper.alert("投资金额不合法！");
//                return;
//            }

//            if (tzjine > tzjine_yue)
//            {
//                jshelper.alert("账户余额不足！");
//                return;
//            }


//            DataRow dr = jiandansql.getonerow("select * from pjkjbxx where pjkjbxxid=" + pjkjbxxid);

//            if ((dr["zhuangtai"].tostr() == "3") == false && (dr["zhuangtai"].tostr() == "4") == false)
//            {
//                jshelper.alert("当前阶段不允许投资！");
//                return;
//            }



//            strSql = " select * from dbo.pjkjbxx  where pjkjbxxid=" + pjkjbxxid;
//            DataTable dt = jiandansql.gettable(strSql);
//            if (dt != null)
//            {
//                if (dt.Rows[0]["biaodileixing"].ToString() == "转债权")
//                {
//                    shengchengzhaiquantouzijilu1(pjkjbxxid, HttpContext.Current.Session["g_user_id"].ToString(), tzjine);
//                }
//            }

//        }


//        //债权投资记录
//        private void shengchengzhaiquantouzijilu1(int pjkjbxxid, string touzirenid, decimal tzjine)
//        {
//            DataRow pjkjbxx = jiandansql.getonerow("SELECT * FROM dbo.pjkjbxx WHERE pjkjbxxid=" + pjkjbxxid);

//            string jiekuanren = pjkjbxx["jiekuanrenid"].ToString();
//            decimal nianlilv = pjkjbxx["nianlilv"].todecimal();
//            DataRow zhaiquan = jiandansql.getonerow("SELECT * FROM [dbo].[zhaiquanzhuanrang] WHERE zhuanrangrenid='" + jiekuanren + "' AND pjkjbxxid=" + pjkjbxxid);
//            string shouchurenid = zhaiquan["zhuanrangrenid"].tostr();
//            int oldpjkjbxxid = zhaiquan["oldpjkjbxxid"].toint32(0);
//            decimal zheranglv = zhaiquan["zheranglv"].todecimal();
//            int oldpjktzjlid = zhaiquan["pjktzjlid"].toint32(0);
//            DataRow tzjl = jiandansql.getonerow("SELECT * FROM dbo.pjktzjl WHERE pjktzjlid=" + zhaiquan["pjktzjlid"].ToString());

//            DataRow dr = jiandansql.getonerow("select * from pjkjbxx where pjkjbxxid=" + oldpjkjbxxid);
//            string sql = @"select email,sysuser.user_id,MOBIL_NO,CardNum,sysuser_kuozhan.TrueName,UsrCustId from sysuser,sysuser_kuozhan
//where sysuser.user_id=sysuser_kuozhan.user_id and sysuser.user_id='" + touzirenid + "'";
//            LxwData has = lxwdbhelper.responseonesql(sql);
//            //生成投资记录
//            int pjktzjlid = jiandansql.getint("insert into pjktzjl(pjkjbxxid,toubiaorenid,zhaiquanrenid,toubiaojine,youxiaojine,toubiaoshijian,zhuangtai) values(" + oldpjkjbxxid + ",'" + touzirenid + "','" + tzjl["pjktzjlid"].tostr() + "'," + tzjine.tostr() + ",0,GETDATE(),'未支付');select @@identity");

//            //生成债权购买记录
//            int debtTradeID = jiandansql.getint(string.Format("INSERT INTO [dbo].[zhaiquanjiaoyi] VALUES({0},'{1}',{2},'{3}',0);select @@identity ", zhaiquan["pjktzjlid"].ToString(), tzjl["toubiaorenid"].ToString(), pjktzjlid, touzirenid));

//            //生成债权转让人和债权购买人的收益计划
//            //IList<PBenefitPlan> plans = P2PHelper.GetBenefitPlansByDebtInvestmentAmount(oldpjkjbxxid, pjktzjlid, oldpjktzjlid, touzirenid, shouchurenid, (decimal)tzjine, nianlilv);
//            //if (plans != null && plans.Count > 0)
//            //{
//            //    string sqlStr = string.Empty;
//            //    for (int i = 0; i < plans.Count; i++)
//            //    {
//            //        sqlStr = string.Format(" INSERT INTO [dbo].[PBenefitPlan] VALUES ({0},'{1}',{2},{3},'{4}',{5},{6}) ", plans[i].ProjectID, plans[i].UserID, plans[i].Principal, plans[i].Interest, plans[i].Deadline.ToShortDateString(), plans[i].PlanStatus, plans[i].phkid);
//            //        HQLHelper.ExecuteNonQuery(CommandType.Text, sqlStr);
//            //    }
//            //}




//            DataRow drzhaiquan = jiandansql.getonerow("select * from zhaiquanzhuanrang where pjkjbxxid=" + pjkjbxxid);
//            string sellcustid = jiandansql.getstring("select UsrCustId from SysUser_kuozhan where user_id='" + tzjl["toubiaorenid"].tostr() + "'");
//            string jiekuanrenkehuhao = jiandansql.getstring("select UsrCustId from pjkjbxx p inner join SysUser_kuozhan s on p.jiekuanrenid=s.user_id where p.pjkjbxxid=" + oldpjkjbxxid);
//            //主动投标记录
//            //跟汇付接口连接。
//            CreditAssign objsend = new CreditAssign();
//            objsend.CmdId = "CreditAssign";
//            objsend.MerCustId = ConfigurationManager.AppSettings["MerCustId"].tostr();
//            objsend.SellCustId = sellcustid; //转让人客户号
//            objsend.CreditAmt = tzjine.todecimal().ToString("#0.00");//债权转让出的本金
//            objsend.CreditDealAmt = tzjine.todecimal().ToString("#0.00");//债权转让承接人付给的金额
//            objsend.BidDetails = ("{\"BidDetails\":[{\"BidOrdId\":\"" + drzhaiquan["OrdId"].tostr() + "\",\"BidOrdDate\":\"" + drzhaiquan["OrdDate"].tostr() + "\",\"BidCreditAmt\":\"" + tzjine.todecimal().ToString("#0.00") + "\",\"BorrowerDetails\":[{\"BorrowerCustId\":\"" + jiekuanrenkehuhao + "\",\"BorrowerCreditAmt\":\"" + tzjine.todecimal().ToString("#0.00") + "\",\"PrinAmt\":\"0.00\",\"ProId\":\"\"}]}]}"); //转让明细
//            //手续费
//            Decimal fenzhangjine = tzjine.todecimal() * (ConfigurationManager.AppSettings["DivFee"].tostr().todecimal() / 100);
//            objsend.Fee = fenzhangjine.ToString("#0.00");
//            objsend.DivDetails = ("[{\"DivAcctId\":\"" + ConfigurationManager.AppSettings["AcctId"].tostr() + "\",\"DivAmt\":\"" + fenzhangjine.ToString("#0.00") + "\"}]"); //分账明细
//            objsend.BuyCustId = jiandansql.getstring("select UsrCustId from sysuser_kuozhan where user_id='" + HttpContext.Current.Session["g_user_id"].ToString() + "'");//债权转让承接人客户号
//            objsend.OrdId = DateTime.Now.ToString("yyyyMMddHHmmssfff");
//            objsend.OrdDate = DateTime.Now.ToString("yyyyMMdd");
//            objsend.BgRetUrl = ConfigurationManager.AppSettings["LocalUrl"] + "ploan/zhaiquanzhuanrangreturnbg.html";
//            objsend.RetUrl = ConfigurationManager.AppSettings["LocalUrl"] + "ploan/zhaiquanzhuanrangreturn.html";

//            #region 写入投资流水、转让流水记录

//            //todo 这里需要插入一条到债权转让流水表里面。对应的表为 Mzhaiquanliushui 表里面。
//            LxwData data = new LxwData();
//            //todo.start 补充完整里面的信息
//            data["User_Id"] = HttpContext.Current.Session["g_user_id"].ToString();
//            data["LogType"] = 0; //0 是代表为处理 1是代表成功 2代表失败
//            data["SetupDate"] = DateTime.Now;
//            data["OrdId"] = objsend.OrdId + "";
//            data["OrdDate"] = objsend.OrdDate + "";//订单日期
//            data["MerCustId"] = ConfigurationManager.AppSettings["MerCustId"].tostr();
//            data["SellCustId"] = sellcustid; //转让人客户号
//            data["CreditAmt"] = tzjine.todecimal().ToString("#0.00");//债权转让出的本金
//            data["CreditDealAmt"] = tzjine.todecimal().ToString("#0.00");//债权转让承接人付给的金额
//            data["BidOrdId"] = drzhaiquan["OrdId"].tostr();//被转让的投标订单号
//            data["BidOrdDate"] = drzhaiquan["OrdDate"].tostr();//被转让的投标订单日期
//            data["BidCreditAmt"] = tzjine.todecimal().ToString("#0.00");//转让金额
//            data["BorrowerCustId"] = jiekuanrenkehuhao;//借款人客户号
//            data["BorrowerCreditAmt"] = tzjine.todecimal().ToString("#0.00");//明细转让金额
//            data["PrinAmt"] = "0.00";//已还款金额
//            data["BorrowerCustId"] = jiekuanrenkehuhao;//借款人客户号
//            data["Fee"] = "0.00";//扣款手续费
//            data["DivAcctId"] = "";//分账账户号         
//            data["DivAmt"] = "";//分账金额
//            data["touzhijiluid"] = pjktzjlid.tostr();//投资记录ID
//            data["BuyCustId"] = objsend.BuyCustId;//承接人客户号
//            data["OrdId"] = objsend.OrdId;//订单号
//            data["OrdDate"] = objsend.OrdDate;//订单日期
//            data["ProId"] = pjkjbxxid.tostr();
//            //得到插入的主键
//            var ret = lxwdbhelper.createorupdate(data, "Mzhaiquanliushuiid");
//            #endregion
//            //插入成功后，把流水的ID传递到实体中 
//            //todo 把主键作为参数传递到汇付的方法里面 返回的地方需要用到这个参数
//            objsend.MerPriv = ret.identity + "";

//            WebPost.Submit(objsend);
//        }


//        /// <summary>
//        /// 债权转让接口return
//        /// </summary>
//        [SkipFilter()]
//        public void zhaiquanzhuanrangreturn()
//        {
//            LoginHelper.top(this);
//            dynamic objrev = new RetCreditAssign();
//            //后台调用，最终要打印出来参数
//            WebPost.ReturnUrl(HttpContext.Current, "OrdId", objrev, true);
//            HttpContext.Response.ContentType = "text/html";
//            LxwData hf = new LxwData();
//            hf["rq"] = DateTime.Now;
//            hf["leixing"] = "CreditAssign";
//            hf["neirong"] = JsonHelper.JsonSerializer<RetCreditAssign>(objrev);
//            lxwdbhelper.createorupdate(hf, "hfid");
//            //代表成功！
//            if (objrev.RespCode == "000")
//            {
//                //更新债权流水
//                LxwData Mzhaiquan = new LxwData();
//                //返回原来债权流水记录的主键
//                Mzhaiquan["Mzhaiquanliushuiid"] = objrev.MerPriv + "";
//                //代表转让成功
//                Mzhaiquan["logtype"] = "1";
//                DataRow dr = jiandansql.getonerow("select * from Mzhaiquanliushui where Mzhaiquanliushuiid=" + objrev.MerPriv);
//                if (int.Parse(dr["LogType"].tostr()) == 0) //如果流水状态为0
//                {
//                    //更新信息
//                    lxwdbhelper.createorupdate(Mzhaiquan, "Mzhaiquanliushuiid");

//                    //更新债权购买记录状态
//                    //int debtjiaoyistatus = jiandansql.getint("SELECT Status FROM zhaiquanjiaoyi WHERE debtpjktzjlid=" + dr["touzhijiluid"].toint32());
//                    //if (debtjiaoyistatus == 0)
//                    //{
//                    //    jiandansql.execute(" UPDATE  zhaiquanjiaoyi SET Status=1 WHERE debtpjktzjlid=" + dr["touzhijiluid"].toint32());
//                    //    gengxinzhaiquanjine(dr["proid"].toint32(), dr["touzhijiluid"].toint32(), "", dr["User_Id"].tostr(), Decimal.Parse(dr["CreditDealAmt"].tostr()), Decimal.Parse("0"));
//                    //}
//                    //jiandansql.execute("update zhaiquanzhuanrang set zhuanrangzhuangtai='转让成功' where pjkjbxxid=" + dr["proid"].toint32());
//                }
//                JSHelper.Redirect("/PUser/message.html?status=1&msg=InitiativeTender");
//            }
//            else
//            {
//                JSHelper.Redirect("/PUser/message.html?status=0&msg=InitiativeTender");
//            }
//        }

//        /// <summary>
//        /// 债权转让接口
//        /// </summary>
//        [SkipFilter()]
//        public void zhaiquanzhuanrangreturnbg()
//        {
//            this.CancelView();
//            dynamic objrev = new RetCreditAssign();
//            //后台调用，最终要打印出来参数
//            WebPost.ReturnUrl(HttpContext.Current, "OrdId", objrev, true);
//            HttpContext.Response.ContentType = "text/html";
//            LxwData hf = new LxwData();
//            hf["rq"] = DateTime.Now;
//            hf["leixing"] = "CreditAssign";
//            hf["neirong"] = JsonHelper.JsonSerializer<RetCreditAssign>(objrev);
//            lxwdbhelper.createorupdate(hf, "hfid");
//            //代表成功！
//            if (objrev.RespCode == "000")
//            {
//                //更新债权流水
//                LxwData Mzhaiquan = new LxwData();
//                //返回原来债权流水记录的主键
//                Mzhaiquan["Mzhaiquanliushuiid"] = objrev.MerPriv + "";
//                //代表转让成功
//                Mzhaiquan["logtype"] = "1";
//                DataRow dr = jiandansql.getonerow("select * from Mzhaiquanliushui where Mzhaiquanliushuiid=" + objrev.MerPriv);
//                if (int.Parse(dr["LogType"].tostr()) == 0) //如果流水状态为0
//                {
//                    //更新信息
//                    lxwdbhelper.createorupdate(Mzhaiquan, "Mzhaiquanliushuiid");
//                    int debtjiaoyistatus = jiandansql.getint("SELECT Status FROM zhaiquanjiaoyi WHERE debtpjktzjlid=" + dr["touzhijiluid"].toint32());
//                    if (debtjiaoyistatus == 0)
//                    {
//                        jiandansql.execute(" UPDATE  zhaiquanjiaoyi SET Status=1 WHERE debtpjktzjlid=" + dr["touzhijiluid"].toint32());
//                        gengxinzhaiquanjine(dr["proid"].toint32(), dr["touzhijiluid"].toint32(), "", dr["User_Id"].tostr(), Decimal.Parse(dr["CreditDealAmt"].tostr()), Decimal.Parse("0"));
//                    }

//                    //jiandansql.execute("update zhaiquanzhuanrang set zhuanrangzhuangtai='转让成功' where pjkjbxxid=" + dr["proid"].toint32());
//                }
//            }
//        }



//        /// <summary>
//        /// 债券投资成功之后更新投资记录、更新已投金额、生成收益计划、投资或者转让后判断标的状态是否满标
//        /// </summary>
//        /// <param name="pjkjbxxid"></param>
//        /// <param name="pjktzjlid"></param>
//        /// <param name="yhids"></param>
//        /// <param name="touzirenid"></param>
//        /// <param name="tzjine"></param>
//        /// <param name="tzjineyh"></param>
//        private void gengxinzhaiquanjine(int pjkjbxxid, int pjktzjlid, string yhids, string touzirenid, decimal tzjine, decimal tzjineyh)
//        {
//            decimal yitoujine = jiandansql.getdecimal("select yitoujine from pjkjbxx where pjkjbxxid=" + pjkjbxxid);//已投金额
//            SqlParameter[] parms = new SqlParameter[]
//                {
//                    new SqlParameter("pjkjbxxid",SqlDbType.Int),
//                    new SqlParameter("yhids",SqlDbType.VarChar,2000),
//                    new SqlParameter("tzrenid",SqlDbType.VarChar,50),
//                    new SqlParameter("tzjine",SqlDbType.Float),//投资总额
//                    new SqlParameter("tzjineyh",SqlDbType.Float),//投资金额中 优惠金额部分
//                    new SqlParameter("tzshijian",SqlDbType.DateTime),
//                    new SqlParameter("yitoujine",SqlDbType.Float),
//                    new SqlParameter("pjktzjlid",SqlDbType.Int),//投资记录ID
//                    new SqlParameter("result",SqlDbType.Int)
//                };
//            parms[parms.Length - 1].Direction = ParameterDirection.Output;
//            parms[0].Value = pjkjbxxid;
//            parms[1].Value = yhids;
//            parms[2].Value = touzirenid;
//            parms[3].Value = tzjine;
//            parms[4].Value = tzjineyh;
//            parms[5].Value = DateTime.Now;
//            parms[6].Value = yitoujine;
//            parms[7].Value = pjktzjlid;
//            parms[8].Value = 0;
//            HQLHelper.ExecuteNonQuery(CommandType.StoredProcedure, "proc_save_touzijilu", parms);



//            #region 生成投资人收益计划 By:JXG

//            int oldpjkjbxxid = jiandansql.getint(" SELECT oldpjkjbxxid FROM zhaiquanzhuanrang WHERE pjkjbxxid=" + pjkjbxxid);

//            int oldpjktzjlid = jiandansql.getint(" SELECT pjktzjlid FROM zhaiquanjiaoyi WHERE debtpjktzjlid=" + pjktzjlid);
//            int shouchurenid = jiandansql.getint(" SELECT toubiaorenid FROM pjktzjl WHERE pjktzjlid=" + oldpjktzjlid);
//            decimal nianlilv = jiandansql.getdecimal(" SELECT nianlilv FROM pjkjbxx WHERE pjkjbxxid=" + pjkjbxxid);
//            IList<PBenefitPlan> plans = P2PHelper.GetBenefitPlansByDebtInvestmentAmount(oldpjkjbxxid, pjktzjlid, oldpjktzjlid, touzirenid, shouchurenid.ToString(), (decimal)tzjine, nianlilv);
//            if (plans != null && plans.Count > 0)
//            {
//                string sqlStr = string.Empty;
//                for (int i = 0; i < plans.Count; i++)
//                {
//                    sqlStr = string.Format(" INSERT INTO [dbo].[PBenefitPlan] VALUES ({0},'{1}',{2},{3},'{4}',{5},{6}) ", plans[i].ProjectID, plans[i].UserID, plans[i].Principal, plans[i].Interest, plans[i].Deadline.ToShortDateString(), plans[i].PlanStatus, plans[i].phkid);
//                    HQLHelper.ExecuteNonQuery(CommandType.Text, sqlStr);
//                }
//            }
//            #endregion

//            //判断转让后是否满标更新标的状态为回款完毕
//            DataRow pjkjxx = jiandansql.getonerow("select * from pjkjbxx where pjkjbxxid=" + pjkjbxxid);
//            if (Decimal.Parse(pjkjxx["yitoujine"].tostr()) == Decimal.Parse(pjkjxx["jiekuanjine"].tostr()))
//            {
//                string sql = "UPDATE pjkjbxx SET zhuangtai='5' WHERE pjkjbxxid=" + pjkjbxxid;
//            }
//        }


//        #endregion
    }
}